from langchain.memory import ConversationBufferWindowMemory

"""
k=2 保存的对话轮数， 
如果超过对话轮数，那么最先进入的对话，将会被删除
"""
window = ConversationBufferWindowMemory(k=2)

window.save_context({"input": "Hello, how are you?"}, {"output": "I'm doing great, thank you!"})
window.save_context({"input": "What is your name?"}, {"output": "My name is LangChain."})
window.save_context({"input": "Where do you reside?"}, {"output": "I reside in your mind."})

print(window.load_memory_variables({"input": "Who are you?"}))